<html>
<head><meta charset="utf-8"><title>assoc const · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/assoc.20const.html">assoc const</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="228069197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/assoc%20const/near/228069197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/assoc.20const.html#228069197">(Feb 27 2021 at 16:50)</a>:</h4>
<p>I'm working on adding associated consts to Chalk (draft PR: <a href="https://github.com/rust-lang/chalk/issues/689">chalk#689</a>). So far I've been mirroring the associated type stuff, so you get things like <code>AssociatedConstDatum</code>, <code>AssociatedConstValueIds</code> etc.<br>
Following through with that approach, we'd end up with something like <code>AliasTy::ConstProjectionTy</code> (naming tbd). Does that make sense? <code>ProjectionTy</code> so far has been specific to associated types, and associated consts are different enough to warrant splitting them instead of trying to group things together.</p>



<a name="228072663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/assoc%20const/near/228072663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/assoc.20const.html#228072663">(Feb 27 2021 at 17:52)</a>:</h4>
<p>what would a <code>ConstProjectionTy</code> be? wouldn't you have a <code>ConstValue::Projection</code> instead? or am I misunderstanding?</p>



<a name="228074860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/assoc%20const/near/228074860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/assoc.20const.html#228074860">(Feb 27 2021 at 18:33)</a>:</h4>
<p><span class="user-mention" data-user-id="129457">@Florian Diebold</span> It would be a new struct, just like how <a href="https://github.com/rust-lang/chalk/blob/a925337c2239821e04fb37c92fdfcc8ebe493907/chalk-ir/src/lib.rs#L1640">ProjectionTy</a> currently represents a type projection. But then with <code>AssocConstId</code> instead of <code>AssocTyId</code></p>



<a name="228074995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/assoc%20const/near/228074995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/assoc.20const.html#228074995">(Feb 27 2021 at 18:36)</a>:</h4>
<p>So in the current <code>AliasTy</code> enum:</p>
<div class="codehilite"><pre><span></span><code>pub enum AliasTy&lt;I: Interner&gt; {
    /// An associated type projection.
    Projection(ProjectionTy&lt;I&gt;),
    /// An opaque type.
    Opaque(OpaqueTy&lt;I&gt;),
}
</code></pre></div>
<p>We have the choice of either adding another variant for const projections, or generalizing <code>ProjectionTy</code> to  also represent const projections as well</p>



<a name="228075594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/assoc%20const/near/228075594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/assoc.20const.html#228075594">(Feb 27 2021 at 18:47)</a>:</h4>
<p>yes, but what I mean is, const projections aren't types, right? so I would expect a new variant to be added to <code>ConstValue</code>, not <code>AliasTy</code></p>



<a name="228075682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/assoc%20const/near/228075682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/assoc.20const.html#228075682">(Feb 27 2021 at 18:48)</a>:</h4>
<p>Ah. <code>ProjectionTy</code> is the type <code>&lt;P0 as TraitName&lt;P1..Pn&gt;&gt;::AssocItem&lt;Pn+1..Pm&gt;</code>,  and <code>ConstProjectionTy</code> (or whatever name we use) would be something like <code>&lt;P0 as TraitName&lt;P1..Pn&gt;&gt;::AssocConst</code></p>



<a name="228075711"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/assoc%20const/near/228075711" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/assoc.20const.html#228075711">(Feb 27 2021 at 18:49)</a>:</h4>
<p>yeah, and that's a value, not a type</p>



<a name="228075796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/assoc%20const/near/228075796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/assoc.20const.html#228075796">(Feb 27 2021 at 18:50)</a>:</h4>
<p>Pretty sure that's a type. <code>TyKind::Alias(AliasTy)</code> which has <code>AliasTy::Projection(ProjectionTy)</code></p>



<a name="228075819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/assoc%20const/near/228075819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/assoc.20const.html#228075819">(Feb 27 2021 at 18:51)</a>:</h4>
<p>ah wait, but for const it's not, is what you're saying</p>



<a name="228075885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/assoc%20const/near/228075885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/assoc.20const.html#228075885">(Feb 27 2021 at 18:52)</a>:</h4>
<p>yeah you're right</p>



<a name="230028505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/assoc%20const/near/230028505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/assoc.20const.html#230028505">(Mar 12 2021 at 13:32)</a>:</h4>
<p>The chalk parser wouldn't be able to see the difference between <code>GenericArg::Ty(Ty::Projection(..))</code> and <code>GenericArg::Const(Const::ProjectionConst(..))</code>, so I guess we should keep those the same in chalk ast, and pick one during lowering</p>



<a name="230028783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/assoc%20const/near/230028783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/assoc.20const.html#230028783">(Mar 12 2021 at 13:34)</a>:</h4>
<p>Some goal examples:</p>
<div class="codehilite"><pre><span></span><code>&lt;T as Iterator&gt;::Item = &lt;T as Iterator&gt;::Item // ProjectionTy
exists&lt;const D&gt; {
    &lt;Foo as Trait&gt;::C = D // ProjectionConst
}
</code></pre></div>



<a name="230030180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/assoc%20const/near/230030180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/assoc.20const.html#230030180">(Mar 12 2021 at 13:45)</a>:</h4>
<p>The downside is that it could lower to the wrong thing if the name is both in scope as assoc type and assoc const, but that's not too important for chalk's internal ast I think, since it's only used for testing</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>